package com.share.config.monitor.druid;

import com.alibaba.druid.support.http.StatViewServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class DruidMonitorConfig {
    @Bean
    public ServletRegistrationBean statViewServlet(){
        ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
        Map<String,String> initParams = new HashMap<>();
        initParams.put("loginUsername","druid");
        initParams.put("loginPassword","druid");
//        initParams.put("allow","");               //默认就是允许所有访问
//        initParams.put("deny","192.168.15.21");   //禁止访问
        bean.setInitParameters(initParams);
        return bean;
    }
}
